#include <Inventor/nodes/SoIndexedFaceSet.h>
#include <Inventor/nodes/SoCoordinate3.h>
#include <iostream>
#include <vector>

using namespace std;

struct HE_face;

typedef struct HE_edge {
	HE_edge();
	HE_edge(int _vert, HE_face *_face);
	int vert;
//	int orig;   // debugging
	HE_edge *pair;
	HE_face *face;
	HE_edge *next;
	HE_edge *prev;
} HE_edge;


typedef struct HE_face {
	enum QuadTypes {
		dart, kite, thick, thin
	};
	HE_face();
	HE_edge *edge;
	int size;
	QuadTypes type;
	HE_edge *tip;
} HE_face;

class Mesh {
private:
	vector<HE_edge *> edges;
	vector<HE_face *> faces;
	vector<float> verts;
	void pair_edges();
	bool face_center(int idx, vector<float> &crd);
	int transformEdgesToVerts(HE_edge *edge, vector<list<pair<int, int> > > &edgeverts);
public:
	Mesh();
	~Mesh();
	float total_curvature();
	bool tt2dk(vector<vector<float> > coeffs);
	bool dk2tt(vector<vector<float> > coeffs);
	bool subdivide(vector<vector<float> > coeffs);
	bool transform2penrose();
	friend std::ostream& operator<<(std::ostream& s, Mesh& he);
	friend bool unloadShape(SoIndexedFaceSet *shape, SoCoordinate3 *coords, Mesh &he);
	friend bool   loadShape(SoIndexedFaceSet *shape, SoCoordinate3 *coords, Mesh &he);
};



